//
//  WJWelcomeViewController.swift
//  WJWeiBo
//
//  Created by wangjun on 16/7/24.
//  Copyright © 2016年 wangjun. All rights reserved.
//

import UIKit
import SDWebImage

class WJWelcomeViewController: UIViewController {

    override func loadView() {
        
        view = bgImageView
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()

    }

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        self.headerImageView.snp_updateConstraints { (make) -> Void in
            
            make.top.equalTo(self.view).offset(100)
        }
        
        UIView.animateWithDuration(1, delay: 1, usingSpringWithDamping: 0.5, initialSpringVelocity: 0, options: [], animations: { () -> Void in
            
            self.view.layoutIfNeeded()
            
            }) { (_ ) -> Void in
                
                // 当上个动画完成后
                UIView.animateWithDuration(0.25, animations: { () -> Void in
                    
                    self.messageLabel.alpha = 1
                    
                    }, completion: { (_) -> Void in
                        // 发送通知 切换根控制器为MainVc
                        NSNotificationCenter.defaultCenter().postNotificationName(weiBoSwitchRootVC, object: "welcome")
                })
        }
        
    }
    
    //MARK: -设置视图
    func setupUI(){
        
        view.addSubview(headerImageView)
        view.addSubview(messageLabel)
        
        headerImageView.snp_makeConstraints { (make) -> Void in
            make.size.equalTo(CGSize(width: 90, height: 90))
            make.centerX.equalTo(view)
            make.top.equalTo(view).offset(400)
        }
        
        messageLabel.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(view)
            make.top.equalTo(headerImageView.snp_bottom).offset(16)
        }
    }
  
    
//MARK: -懒加载控件
    //背景图片
    private lazy var bgImageView:UIImageView = UIImageView(imgName: "ad_background")
    
    private lazy var headerImageView:UIImageView = {
        
        let image = UIImageView(imgName: "avatar_de  fault_big")
        image.sh_setImage(WJUserAccountViewModel.shareTools.userAccoun?.avatar_large, placeholderImgName: "avatar_default_big")
        image.layer.borderColor = ThemeColor.CGColor
        image.layer.borderWidth = 2
        image.layer.cornerRadius = 45
        image.layer.masksToBounds = true
        return image
    }()
    
    private lazy var messageLabel: UILabel = {
        let lab = UILabel(textColor: UIColor.darkGrayColor(), textFont: 18)
        lab.text = "欢迎回来"
        lab.textAlignment = .Center
        lab.alpha = 0
        return lab
    }()

}
